﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;

public partial class Controls_Cruise_ctrCruiseCatDetail : System.Web.UI.UserControl
{
    private int nCurrentlanguage = Support.GetCurrentLanguage();
    private int nRegion = 0;
    private int nType = 0;
    private int nCountry = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            this.Initdata();
        }
    }
    private void Initdata()
    {
        lnkShowall.Text = MultipleLanguage.GETMORECRUISE[nCurrentlanguage - 1];
        lnkShowall.NavigateUrl = "~/CruiseCategory.aspx?" + Config.COUNTRY + "=" + nCountry + "&" + Config.CRUISEREGION + "=" + nRegion + "&" + Config.CRUISETYPE + "=" + nType;
        this.TopDeal();
    }
    public void setCruiseRegion(int Counry, int CruiseRegion, int nCruiseType, int Pagesize)
    {
        nRegion = CruiseRegion;
        nType = nCruiseType;
        nCountry = Counry;
      
    }
    private void TopDeal()
    {
        Cruise objCruise = new Cruise();
        DataTable dtbCruise = new DataTable();
        int nPageCount = 0;
        int nItem = ConvertData.ConvertToInt(Request.QueryString[Config.CRUISEID]);
        dtbCruise = objCruise.Search(5, nItem, nCountry, nRegion, nType, 1, 1, 5, ref nPageCount);
        if (dtbCruise.Rows.Count == 0)
            lblLuxury.Visible = false;
        else
        {
            if (nType == 2)
                lblLuxury.Text = MultipleLanguage.LUXURY_CRUISETYPE[nCurrentlanguage - 1];
            else if (nType == 1)
                lblLuxury.Text = MultipleLanguage.PRIVATE_CRUISETYPE[nCurrentlanguage - 1];
        }

        
        rptCruise.DataSource = dtbCruise;
        rptCruise.DataBind();

    }

    protected void rptCruise_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);

        switch (strCommand)
        {
            case "image":
                nCountry = ConvertData.ConvertToInt(Request.QueryString[Config.COUNTRY]);
                string sDetail = Config.ROOT + Pages.FrontEnds.CRUISE_DETAIL + "?" + Config.CRUISEID + "=" + nID + "&cid=" + nCountry;
                Response.Redirect(sDetail);
                break;
        }
    }

    protected void rptCruise_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {

            HyperLink lnkCruiseName = (HyperLink)e.Item.FindControl("lnkCruiseName");
            ImageButton imgbtnCruise = (ImageButton)e.Item.FindControl("imgCruise");
            HyperLink lnkReadAll = (HyperLink)e.Item.FindControl("lnkReadAll");
            Label lblAddress = (Label)e.Item.FindControl("lblAddress");
            Label lblInitContent = (Label)e.Item.FindControl("lblInitContent");
            Label lblDuration = (Label)e.Item.FindControl("lblDuration");
            Label lblPrice = (Label)e.Item.FindControl("lblPrice");

            string sPriceFrom = "$" + ConvertData.ConvertToString(Support.FormatCurrency(DataBinder.Eval(e.Item.DataItem, "PriceFrom"))).Replace(".", "");
            string sPriceTo = "$" + ConvertData.ConvertToString(Support.FormatCurrency(DataBinder.Eval(e.Item.DataItem, "PriceTo"))).Replace(".", "");

            lnkReadAll.Text = MultipleLanguage.LNK_READMORE[nCurrentlanguage - 1];
            lnkCruiseName.NavigateUrl = Config.ROOT + Pages.FrontEnds.CRUISE_DETAIL + "?" + Config.CRUISEID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CruiseID")) + "&cid=" + nCountry;
            lnkReadAll.NavigateUrl = Config.ROOT + Pages.FrontEnds.CRUISE_DETAIL + "?" + Config.CRUISEID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CruiseID")) + "&cid=" + nCountry;
          
            imgbtnCruise.ImageUrl = Config.ROOT + Config.IMAGE_CRUISE_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Images"));
            imgbtnCruise.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CruiseID"));
            string sInitContent = "";
            switch (nCurrentlanguage)
            {
                case 1:
                    lblPrice.Text = "Giá từ: " + " " + sPriceFrom +  " "+ " đến" + " " + sPriceTo;
                    lblDuration.Text = "Duration: " + this.GetDuration(ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "CruiseDurationID")));
                    lnkCruiseName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title1"));
                    //lblAddress.Text = "Address:" + " " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Address1"));
                    sInitContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent1"));
                    break;
                case 2:
                    lblPrice.Text = "Price from: " + " " + sPriceFrom + " " + "to" + " " + sPriceTo;
                    lblDuration.Text = "Duration: " + this.GetDuration(ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "CruiseDurationID")));
                    lnkCruiseName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title2"));
                    //lblAddress.Text = "Address:" + " " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Address2"));
                    sInitContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent2"));
                    break;
                case 3:
                    lblPrice.Text = "Price from: " + " " + sPriceFrom + " " + "to" + " " + sPriceTo;
                    lblDuration.Text = "Duration: " + this.GetDuration(ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "CruiseDurationID")));
                    lnkCruiseName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title3"));
                    //lblAddress.Text = "Dirección:" + " " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Address3"));
                    sInitContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent3"));
                    break;
            }
            sInitContent = ConvertData.TruncateString(sInitContent, 270) + "...";
            lblInitContent.Text = sInitContent;

            //HtmlImage lblValStarRating = (HtmlImage)e.Item.FindControl("lblValStarRating");
            //Support.GetStar(lblValStarRating, ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "StarRating")));
        }
    }

    private string GetDuration(int nID)
    {
        TourDuration obj = new TourDuration();
        obj.LoadById(nID);
        string sDuration = "";
        switch (nCurrentlanguage)
        { 
            case 1:
                sDuration = obj.Data.DurationDescription1;
                break;
            case 2:
                sDuration = obj.Data.DurationDescription2;
                break;
            case 3:
                sDuration = obj.Data.DurationDescription3;
                break;
        }
        return sDuration;
    }

  
}